<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../ui/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../ui/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="candyForm">
    <input name="id" id="id" style="display: none;"/>
    <input type="text" name="orgName" id="orgName" class="layui-hide" value=""/>
    <div class="layui-form-item">
        <label class="layui-form-label required">用户真实姓名</label>
        <div class="layui-input-block">
            <input type="text" name="realName" id="realName" lay-verify="required" lay-reqtext="用户真实姓名不能为空" placeholder="请输入用户真实姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">登录名</label>
        <div class="layui-input-block">
            <input type="text" name="loginName" id="loginName" lay-verify="required" lay-reqtext="登录名不能为空" placeholder="请输入登录名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="text" name="password" id="password" placeholder="请输入密码" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">所属机构</label>
        <div class="layui-input-block">
            <input type="text" name="orgId" id="orgId" lay-filter="orgId" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">序号</label>
        <div class="layui-input-block">
            <input type="text" name="orderNum" id="orderNum" placeholder="请输入序号" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="gender" value="1" title="男">
            <input type="radio" name="gender" value="2" title="女">
            <input type="radio" name="gender" value="0" title="未知" checked="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">手机号码</label>
        <div class="layui-input-block">
            <input type="text" name="telphone" id="telphone" lay-verify="required|phone|number" lay-reqtext="手机号码不能为空" placeholder="请输入手机号码" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" id="email" lay-verify="required|email" lay-reqtext="邮箱不能为空" placeholder="请输入邮箱" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">微信OpenID</label>
        <div class="layui-input-block">
            <input type="text" name="weixinOpenid" id="weixinOpenid" placeholder="请输入微信OpenID" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../../ui/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../ui/layuimini/js/lay-config.js"></script>
<script>
    layui.use(['form','auth','treeSelect'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        var treeSelect= layui.treeSelect;
        var id = getQueryString("id");
        var submitType="POST";
        var api="/api/sys/user";
        if(typeof(id)!="undefined" && id!=null && id.length>=0)
        {
            var settings = {
                "url": api+"/"+id,
                "method": "GET"
            };
            $.ajax(settings).done(function (res) {
                $("#loginName").attr("disabled",true);
                form.val("candyForm", res.data);
                loadTree(true);
            });
            submitType="PUT"
        }
        else {
            loadTree(false);
        }
        function loadTree(isInit)
        {
            treeSelect.render({
                // 选择器
                elem: '#orgId',
                // 数据
                data: "/api/sys/organzation/tree",
                // 异步加载方式：get/post，默认get
                type: 'get',
                // 占位符
                placeholder: '请选择机构',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                // 点击回调
                click: function(data){
                    form.val("candyForm", {"orgName":data.current.name,"orgId":data.current.id});
                },
                // 加载完成后的回调函数
                success: function (d) {
                    if(isInit) {
                        treeSelect.checkNode("orgId", form.val("candyForm")["orgId"]);
                    }
                }
            });
        }
        //监听提交
        form.on('submit(saveBtn)', function (data) {
			var settings = {
			  "url": api,
			  "method": submitType,
              "contentType":"application/json",
			  "data": JSON.stringify(data.field),
			};
			$.ajax(settings).done(function (response) {

			    if(response.code==200)
                {
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                    parent.reload();
                }
			    else
                {
                    layer.alert(response.msg,{
                        icon: 2
                    });
                }
			}); 
            return false;
        });
    });


</script>
</body>
</html>